#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void print(int* a,int n)
{
	int i = 0;
	for(i = 0;i < n;i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}
void InsertSort(int* a, int n)
{
	int i = 0;
	for (i = 0;i < n - 1;i++)
	{
		int end = i;
		int tmp = a[end + 1];
		while (end >= 0)
		{
			if (a[end] > tmp)
			{
				a[end + 1] = a[end];
				end--;
			}
			else
			{
				break;
			}
		}
		a[end + 1] = tmp;
	}
}

void ShellSort(int* a, int n)
{
	int gap = n;
	while(gap>1)
	{
		gap = gap / 2;
		int i = 0;
		for (i = 0;i < n - gap;i++)
		{
			int end = i;
			int tmp = a[end + gap];
			while (end >= 0)
			{
				if (a[end] > tmp)
				{
					a[end + gap] = a[end];
					end=end-gap;
				}
				else
				{
					break;
				}
			}
			a[end + gap] = tmp;
		}
	}
}
int main()
{
	int a[] = {99,44,11,67,34,90,44,33,11,42,7};
	int n = sizeof(a) / sizeof(a[0]);
	print(a, n);
	ShellSort(a, n);
	print(a,n);
	return 0;
}